import {Suspense} from "react"
import { Route, Switch, Redirect} from 'react-router-dom'
let RouterView = (props)=>{
    console.log(props,1111)
    let {RouterList} = props;
    let routerList = RouterList.filter(item=>!item.to)
    let redirect =  RouterList.filter(item=>item.to)[0]
    console.log(routerList,redirect)
    return (
        <Suspense fallback={<div>...加载中</div>}>
            <Switch>
                {
                    routerList&&routerList.length?routerList.map((item,index)=>{
                        return <Route path={item.path} key={index} render={(routerProps)=>{
                                return <item.component {...routerProps} ></item.component>
                        }}></Route>
                    }):"暂无路由"
                }
                {
                    redirect?<Redirect  from={redirect.from} to={redirect.to}></Redirect>:"暂无重定向"
                }
            </Switch>
        </Suspense>
    )
}
export default RouterView